package com.avic.rong.activity.mine;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.avic.rong.BaseActivity;
import com.avic.rong.R;
import com.avic.rong.fragment.release.QuestAnFragment;
import com.avic.rong.fragment.release.ReleaseFragment;
import com.avic.rong.fragment.release.VideoFragment;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

//我的服务-我的发布
public class MyReleaseActivity extends BaseActivity {

    @BindView(R.id.tablayout_release)
    SlidingTabLayout tablayout_release;
    @BindView(R.id.vp_release)
    ViewPager vp_release;
    @BindView(R.id.img_return)
    ImageView img_return;

    private String[] titles = {"文章", "问答","视频"};
    private ArrayList<Fragment> fragments = new ArrayList<>();

    @Override
    protected int getContentViewId() {
        return R.layout.activity_my_release;
    }

    @Override
    protected void initView() {
        int publishType = getIntent().getIntExtra("publishType", -1);
        isNeedTitle = false;

        fragments.add(new ReleaseFragment());
        fragments.add(new QuestAnFragment());
        fragments.add(new VideoFragment());

        MyPageAdapter myPageAdapter = new MyPageAdapter(getSupportFragmentManager());
        vp_release.setAdapter(myPageAdapter);
        tablayout_release.setViewPager(vp_release);
        vp_release.setOffscreenPageLimit(fragments.size());
        if (publishType!=-1){
            tablayout_release.setCurrentTab(2);
        }

    }

    @Override
    protected void addListener() {

    }

    @OnClick(R.id.img_return)
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.img_return:
                finish();
                break;
        }
    }

    public class MyPageAdapter extends FragmentPagerAdapter {
        public MyPageAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            return fragments.get(i);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    }

    public static Intent queryIntent(Context context) {
        Intent intent = new Intent(context, MyReleaseActivity.class);
        return intent;
    }
    //文章  0    问答   1     视频   2
    public static Intent queryIntentVideo(Context context,int postion) {
        Intent intent = new Intent(context, MyReleaseActivity.class);
        intent.putExtra("publishType",postion);
        return intent;
    }
}
